package com.cet.spring_batch_study.jobs.endOfDay;

import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;

import java.security.SecureRandom;
import java.util.concurrent.TimeUnit;

/**
 * @author NSOC
 */

public class LongTimeElapseTaskletStep implements Tasklet {
    @Override
    public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {

        JobParameters jobParameters = contribution.getStepExecution().getJobParameters();
        Long loopTimes = jobParameters.getLong("loop.times");
        System.out.println("实际运行时times参数值为" + loopTimes);
        for (long i = 0L; i < loopTimes; i++) {
            TimeUnit.SECONDS.sleep(1);
            System.out.println("第" + (i+1) + "次打印！");
        }
        return RepeatStatus.FINISHED;
    }
}
